/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*/
#include "format_field.h"
#include "vpc_format_def.h"

static int32_t yuv400_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV_400) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400, RANK_BUTT);

    SET_PIXEL_FMT(D8, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_22, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400fp32_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if ((format != VPC_PIPE_PIXEL_FORMAT_YUV_400) &&
        (format != VPC_PIPE_PIXEL_FORMAT_YUV400_FP32)) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_FP32, RANK_BUTT);

    SET_PIXEL_FMT(D32, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400fp16_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_FP16) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_FP16, RANK_BUTT);

    SET_PIXEL_FMT(D16, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400fp64_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_FP64) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_FP64, RANK_BUTT);

    SET_PIXEL_FMT(D64, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400bf16_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_BF16) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_BF16, RANK_BUTT);

    SET_PIXEL_FMT(D16, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400s16_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_INT16) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_INT16, RANK_BUTT);

    SET_PIXEL_FMT(D16, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400s32_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_INT32) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_INT32, RANK_BUTT);

    SET_PIXEL_FMT(D32, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400s64_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_INT64) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_INT64, RANK_BUTT);

    SET_PIXEL_FMT(D64, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400u16_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_UINT16) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_UINT16, RANK_BUTT);

    SET_PIXEL_FMT(D16, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400u32_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_UINT32) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_UINT32, RANK_BUTT);

    SET_PIXEL_FMT(D32, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400u64_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_UINT64) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_UINT64, RANK_BUTT);

    SET_PIXEL_FMT(D64, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

static int32_t yuv400s8_format_info_init(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t format)
{
    if (format != VPC_PIPE_PIXEL_FORMAT_YUV400_INT8) {
        return 1;
    }

    SET_VPC_PIC_FMT(YUV400_INT8, RANK_BUTT);

    SET_PIXEL_FMT(D8, IDEL, IDEL);
    SET_PIXEL_STEP(NUM_1, NUM_1); // xstep/ystep
    SET_DOWN_SAMPLE_COEFF(NUM_0, NUM_0, NUM_128, NUM_128, NUM_0, NUM_0); // 下采样系数
    SET_UVUP_EN(NUM_1); // 滤波开关
    SET_PORT_DU(NUM_88, NUM_11, NUM_11); // DU配置
    SET_PLANN_FMT(BUTT_PLANNAR);
    return 0;
}

int32_t vpc_pipe_init_gray_field_format_info(vpc_fmt_info_t *fmt_info, vpc_pipe_pic_fmt_t fmt)
{
    CHECK_SUCC_RET(yuv400_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400u16_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400u32_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400u64_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400fp16_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400bf16_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400fp32_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400fp64_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400s8_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400s16_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400s32_format_info_init(fmt_info, fmt));
    CHECK_SUCC_RET(yuv400s64_format_info_init(fmt_info, fmt));

    return 1;
}
